<template>
  <!--法规名称新增/编辑弹窗-->
  <a-modal  :maskClosable="false"
            :title="mdl.dialogTitleMap[mdl.dialogStatus]"
            :width="1000"
            @ok="mdl.dialogStatus === 'create' ? createData() : updateData()"
            v-model="mdl.visible"
            :confirm-loading="loading"
  >
    <a-form>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="名称"
      >
        <a-input placeholder="" v-model="mdl.formData.name"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="介绍"
      >
        <a-textarea :rows="20" v-model="mdl.formData.intro"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
  import {infoDocIinsert,infoDocIup} from '@/api/invoice'
  export default {
    components: {

    },
    props: {
      /*   -------弹窗--------*/
      mdl: [Array,Object]
    },
    data() {
      return {
        loading: false
      }
    },
    inject: ['upShow'],

    created() {

    },
    watch: {

    },
    computed: {

    },
    methods: {
//          新增
      createData() {
          this.loading = true
        const parameter = {
          name: this.mdl.formData.name,
          intro: this.mdl.formData.intro
        }
        infoDocIinsert(parameter).then(res => {
            this.loading = false
          if(res.code === 200) {
            this.upShow(1,"新增成功")
            this.mdl.visible = false
            this.$emit('handleSearch')
          } else {
            this.upShow(2,res.msg)
          }
        }).catch(err => {
          this.loading = false
          this.upShow(2)
        })
      },
//      编辑
      updateData() {
        this.loading = true
        const parameter = this.mdl.formData
        infoDocIup(parameter).then(res => {
          this.loading = false
          if(res.code === 200) {
            this.upShow(1,"编辑成功")
            this.mdl.visible = false
            this.$emit('handleSearch')
          } else {
            this.upShow(2,res.msg)
          }
        }).catch(err => {
          this.loading = false
          this.upShow(2)
        })
      },
    }
  }
</script>